package com.clps.algorithm.chapter05.变位词组;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class demo02 {
    public static void main(String[] args) {

    }

    public List<List<String>>  groupAnagrams(String[] strs){
        Map<String, List<String>> groups = new HashMap<>();
        for (String str : strs) {
            char[] charArray = str.toCharArray();
            Arrays.sort(charArray);
            String sorted = new String(charArray);
            groups.putIfAbsent(sorted,new LinkedList<String>());
            groups.get(sorted).add(str);
        }

        return  new LinkedList<>(groups.values());

    }
}
